/**
 * Created by XGJ on 2017/9/22.
 */

import {Component} from "@angular/core";
import {UserInFo} from "../../model/userInfo";
import {NavController, ModalController, AlertController} from "ionic-angular";
import {AboutPage} from "./about/about";
import {LoginModelPage} from "../login/login";
import {ContactPage} from "../component/contact-component/contact.component";
@Component({
    selector:'page-main',
    templateUrl:'main.html'
})

export class MainPage{
    userinfo:UserInFo=new UserInFo;
    constructor(
        public navCtrl:NavController,
        private modalCtrl:ModalController,
        private alertCtrl:AlertController
    ){}

    ionViewWillEnter(){
    }

    login(){
        let modul=this.modalCtrl.create(LoginModelPage);
        modul.present();
        modul.onDidDismiss(result =>{
            console.log(result);
            this.userinfo = result;
        })
    }

    logout(){
        let alert = this.alertCtrl.create({
            title:"退出登录",
            cssClass:'logout-alert',
            buttons:[
                {
                    text: '取消',
                    cssClass:'logout-cancel'
                },
                {
                    text:'确定',
                    cssClass:'logout-ok',
                    handler:() =>{
                        this.userinfo = new UserInFo;
                    }
                }
            ]
        });

        alert.present();
    }

    about(){
        this.navCtrl.push(AboutPage);
    }

    learn(){
        this.navCtrl.push(ContactPage);   //跳转界面
    }

}
